import React from 'react'
import {
  increment,
  decrement,
  ifOddIncrement,
  waitIncrement
}from '../../store/slice/countSlice'
import { useDispatch, useSelector } from 'react-redux'

export default function Count() {
  const count = useSelector(state => state.count.count)
  const dispatch=useDispatch()
  const incrementHandle = () => {
    dispatch(increment(1))
  }
  const decrementHandle = () => {
    dispatch(decrement(1))
  }

  const ifOddIncrementHandle = () => {
      dispatch(ifOddIncrement(1))
  }
  const waitIncrementHandle = () => {
    dispatch(waitIncrement(1))
  }

  return (
    <div>
      <h2>我是count要累加的值{count}</h2>
      <button onClick={incrementHandle}>累加</button>
      <button onClick={decrementHandle}>累减</button>
      <button onClick={ifOddIncrementHandle}>如果是奇数才累加</button>
      <button onClick={waitIncrementHandle}>等待两秒在累加</button>
    </div>
  )
}
